class Student:

    def __init__(self, name, age):
        self.name = name  # 实例属性
        self.__age = age  # 实例属性
    # 先有getxxx
    @property
    def age(self):
        return self.__age
    # 再有set,因为先有get,再有set
    @age.setter
    def age(self, age):
        if age > 0 and age <=120:
            self.__age = age
        else:
            print('年龄不合法')


    # 定义公有set和get方法
    def setAge(self, age):
        if age > 0 and age <=120:
            self.__age = age
        else:
            print('年龄不合法')

    def getAge(self):
        return self.__age

    def __str__(self):
        return '姓名：{}，年龄：{}'.format(self.name, self.__age)

s = Student('zhansan', 18)
s.name = 'wangwu'
print(s.name)

print(s.age)
print(s.__dir__())
# s.setAge(30)
# print(s.getAge())










